package com.example.usernamee.myhandler;

import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

public class ImgchangetextActivity extends AppCompatActivity {
String str[]={"习主席欧美行”漫评③：海湖庄园会晤为中美关系指明方向",
        "“我与文化自然遗产的故事”微视频征集",
        "首次“习特会” 这些成果不可不知",
        "[面对面]中国仪仗兵","“懂电”大师拜克明：用小发明为企业挽回千万元损失"};
    int xx=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imgchangetext);
        final TextView tv=(TextView)findViewById(R.id.tv);
        final Handler mandler=new Handler(){
            /**
             * Subclasses must implement this to receive messages.
             *
             * @param msg
             */
            @Override
            public void handleMessage(Message msg) {
                if (msg.what==209){
                    tv.setTextColor(Color.BLUE);
                    tv.setText(str[xx++%str.length]);
                }
                super.handleMessage(msg);
            }
        };
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                mandler.sendEmptyMessage(209);
            }
        },0,3000);
    }
}
